import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const userToken = 'TOUTIAO_USER'
import {getItem,setItem} from '@/utils/storage'
export default new Vuex.Store({
  state: {
	user:getItem(userToken),
	// 控制缓存
	cachePages:['layout']
	
  },
  mutations: {
	setUser(state,data){
		
		state.user = data
		setItem(userToken,state.user)
	},
	
	addCachePages(state,pageName){
		if(!state.cachePages.includes(pageName)){
			state.cachePages.push(pageName)
		}
	},
	// 登录时清除缓存
	removeCachePages(state,pageName){
		const index = state.cachePages.indexOf(pageName)
		console.log(index)
		if(index !== -1){
			state.cachePages.splice(index,1)
		}
	}
  },
  getters:{
	 
  },
  actions: {

  }
})
